<?php

require_once("kra_base.php");

class qimo {

    private $_user_fds = array(
		'uid' => 'uid',
		'nickname' => 'name',
		'gender' => 'sex',
		'thumbnail_url' => 'pic_middle'
    );
	private $_minik = false;
	private $_userinfo = array();

    public function __construct($api_key = "", $api_secret = "") {
		include_once 'minik.php';
		$this->_minik = new MINIK($api_secret,$api_key);
    }

	public function request_permissions($callback_url = "", $perms = array()) {
	
    }

    function get_uid() {
		if(!$this->_userinfo)
		{
			$this->_minik->Init(0);
			$this->_userinfo = $this->_minik->GetUserInfo();
		}

		return $this->_userinfo["uid"];
    }

    public function me($field = array()) {
		if(!$this->_userinfo)
		{
			$this->_minik->Init(0);
			$this->_userinfo = $this->_minik->GetUserInfo();
		}

		$ret = array();
		foreach ($field as $fd) $ret[$fd] = $this->_userinfo[$this->_user_fds[$fd]];

		return $ret;
    }

    public function friends($page = 1, $pagesize = 20, $hasapp = 0, $fullinfo = 0) {
		$ret = array();
		$this->_minik->Init(1);
		$friends = $this->_minik->GetAppFriendList();
		foreach($friends as $f)
		{
			$i = intval($f["uid"]);
			if(!$i) continue;

			foreach ($this->_user_fds as $fd => $ofd) $ret[$i][$fd] = $f[$ofd];
		}
		return $ret;
    }

    public function feed($title = "", $content = "", $imgs = "") {
		return false;
    }

    public function invite($to_uid = 0, $content = "") {
		return false;
    }

	public function isfan() {}

	public function becomefan() {}

}

?>
